{"componentChunkName":"component---src-pages-blog-index-js","path":"/blog/","result":{"data":{"allMarkdownRemark":{"edges":[{"node":{"frontmatter":{"title":"The best possible IIIT Internet setup","description":"Setting up smart VPN and hotspot, aimed towards IIIT students","slug":"/blog/IIIT-network-setup","date":"2020-05-19","tags":["IIIT","Network","Guides"],"draft":false},"html":"<p>Hello!</p>\n<p>In this post, I am going to explain how to set up a seamless internet experience if you are using IIIT network.</p>\n<p>We are going to cover the following things:</p>\n<ul>\n<li><a href=\"#Advantages%20of%20using%20a%20VPN\">Advantages of using a VPN</a></li>\n<li><a href=\"#Network%20interfaces%20and%20kernel%20magic\">Network interfaces and kernel magic</a></li>\n<li><a href=\"#Routing%20Table\">Routing Table</a></li>\n<li><a href=\"#Creating%20a%20WiFi%20Hotspot%20with%20create_ap\">Creating a WiFi Hotspot with create_ap</a></li>\n<li><a href=\"#Steps%20for%20Automating\">Steps for Automating</a></li>\n<li><a href=\"#Conclusion\">Conclusion</a></li>\n</ul>\n<p>PS: This post has more theory then needed and has some very simple tutorial steps,\nyou can <a href=\"#Steps%20for%20Automating\">skip to the steps to follow at the bottom.</a></p>\n<h2 id=\"Advantages of using a VPN\"> Advantages of using a VPN </h2>\n<p>Using a VPN service allows you to hide your information from anyone trying to snoop on you.\nIt also allows you to access websites and services blocked on your network. You can also use VPNs to escape Geofencing.</p>\n<ul>\n<li>Since Port 22 is blocked, you won't be able to SSH to any device outside the IIIT Network</li>\n<li>Since UDP is blocked you won't be able to play PUBG on your phone (or any other game)</li>\n<li>Since we live in India, you can only access content on Netflix India</li>\n</ul>\n<p>But a bonus for IIIT network is that it also protects you from frequent internet outages when the proxy server is overloaded.</p>\n<div style=\"position:relative;height:0;overflow:hidden;max-width:100%;padding-bottom:56.25%;background-color:white;\">\n<img src=\"https://upload.wikimedia.org/wikipedia/commons/thumb/b/bb/Proxy_concept_en.svg/1280px-Proxy_concept_en.svg.png\" alt=\"proxy-img\" style=\"position:absolute;top:0;left:0;width:100%;height:100%;\">\n</div>\n<center><span>Working of a Proxy Server</span></center>\n<p>When the proxy server is overloaded each time Alice wants to talk to Bob it has to wait for proxy to process its\nrequest. So each new request has to fight for resources and cause more congestion at the proxy.\nThis is often the case with the proxy server at IIIT, even after the Student SysAdmins have tried their best to make sure it works seamlessly.</p>\n<p>But what if we could make a connection with ONE request and use the same connection as a tunnel for all other requests?\nThis is where a VPN comes in.</p>\n<div style=\"position:relative;height:0;overflow:hidden;max-width:100%;padding-bottom:30.33%;background-color:white;\">\n<img src=\"/vpn-1.jpg\" alt=\"vpn-img\" style=\"position:absolute;top:0;left:0;width:100%;height:100%;\">\n</div>\n<center><span>Working of a VPN</span></center>\n<p>(PS: I use NordVPN, but virtually any VPN service works in the same way)</p>\n<p>When a VPN connection is started, a tunnel is set up between your machine and the VPN server.\nAll data flowing through this tunnel is encrypted.</p>\n<p>Since the VPN server has internet access with no restrictions on websites or services.\nIt can forward your requests to the internet and return the response.</p>\n<p>Any website you visit while connected to the VPN will see your IP as the VPN server IP and location as the server's location.</p>\n<p>This is all good and simple to set up. You just need the OpenVPN config file for the VPN server you want to connect to.\nMake sure to use a config which uses TCP port 443 ( or any other unblocked port )</p>\n<p>Using port 443 is your best bet as it is used to set up HTTPS for connection and thus will never be blocked.</p>\n<p>So now the VPN is set up and working.\nAll the websites you visit are routed through the VPN server giving you limitless freedom.</p>\n<p>But if you try to access any website on the IIIT intranet (like: <a href=\"https://proxy.iiit.ac.in\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Proxy Status</a>, <a href=\"https://gitlab.iiit.ac.in\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">IIIT GitLab</a> or <a href=\"https://intranet.iiit.ac.in\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Intranet Index</a> ) it won't work.</p>\n<p>This is because these are hosted inside the IIIT network and are not available on the internet.</p>\n<h2 id=\"Network interfaces and kernel magic\"> Network interfaces and kernel magic </h2>\n<p>Each laptop has one (or more) hardware network cards. These cards allow the machine to connect to networks. Usually, a laptop will contain an ethernet card and a wireless network card. So you can connect to both at once.\nThese cards only allow you to join one hardware network at a time, which is why you can connect to a wifi or use your device as a wifi hotspot but not do both at the same time.</p>\n<p>These cards are your <em>physical</em> network interfaces, but the kernel represents these as <em>software</em> network interfaces.</p>\n<p>To see all the network interfaces active right now on your machine you can run the following command</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\">$ <span class=\"token function\">ip</span> <span class=\"token function\">link</span> show</code></pre></div>\n<p>This command will list all the network interfaces or <code class=\"language-text\">links</code> according to your kernel.</p>\n<p>For a ubuntu laptop, there will usually be 3 interfaces.</p>\n<ol>\n<li>Loopback (<code class=\"language-text\">lo</code>)</li>\n<li>Ethernet (<code class=\"language-text\">enp2s0</code> or similar)</li>\n<li>Wireless (<code class=\"language-text\">wlp3s0</code> or similar)</li>\n</ol>\n<p>There may be more based on other services running on the machine and the hardware attached, for example, docker will setup the docker0 network interface. If you are interested in learning more about how docker networking works let me know in the comments!</p>\n<p>This is possible because it is not necessary for each software network interface to be attached to a network card. This allows us to set up virtual network interfaces. This is in fact how OpenVPN works. It makes a <a href=\"https://en.wikipedia.org/wiki/TUN/TAP\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">TUN/TAP </a> and connects this to a <em>Virtual</em> <em>Private</em> <em>Network</em>.</p>\n<p>In this almost magical setup, the kernel treats this virtual TUN/TAP device as it would any other network device. It can send data through this interface even though the underlying piping goes through your hardware network via ethernet.</p>\n<div style=\"position:relative;height:0;overflow:hidden;max-width:100%;padding-bottom:56.25%;background-color:white;\">\n<img src=\"/openvpn-scheme.svg\" alt=\"openvpn-scheme\" style=\"position:absolute;top:0;left:0;width:100%;height:100%;\">\n</div>\n<center><span>OpenVPN TUN/TAP Piping</span></center>\n<p>Each interface may have one or more IP addresses associated with it that are valid in their corresponding network.</p>\n<p>If your machine (Machine A) is connected to IIIT network via ethernet and connected to a VPN, your eth/enp2s0 interface will have an IP address that is valid inside the IIIT network and your TUN/TAP interface will have an IP address valid inside your VPN.</p>\n<p>If another machine (Machine B) is connected to the same VPN, A &#x26; B can talk to each other using the respective VPN IP address.</p>\n<p>Fun Fact: The DHCP server of IIIT assigns IP addresses to you based on where you are on campus. If you are connected via the IIIT VPN you will get an IP that looks like <code class=\"language-text\">10.11.0.X</code>.</p>\n<h2 id=\"Routing Table\"> Routing Table </h2>\nSo we now know what network interfaces are, but how does the kernel determine what packets to send on which interface?\n<p>Each device in a network has its own routing table which allows it to determine <em>where</em> to send the packet.</p>\n<p>To see the routing table for your machine run the following command.</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">ip</span> route show</code></pre></div>\n<div class=\"gatsby-code-title\">Example Output</div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">default via 192.168.1.1 dev wlp3s0 proto dhcp metric 600\n169.254.0.0/16 dev wlp3s0 proto kernel scope link metric 1000\n192.168.1.0/24 dev wlp3s0 proto kernel scope link src 192.168.1.22 metric 600</code></pre></div>\n<p>Going over all the details of this routing table would be tedious, so we will focus on what matters here.\nThe format of each line is roughly</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;target IP range> dev &lt;device or interface name> ..{other params}</code></pre></div>\n<p>Whenever a packet is leaving from your machine, the routing table checks the destination of the packet and selects the route which matches the target IP range. Playing with the routing table allows us to select where to send packets depending on the destination!</p>\n<p>If no rule matches the destination the packet is sent through the default route which is the first line in the above example output.</p>\n<p>This means that we can set it up in such a way that if the packet is headed to the internet we send it through the TUN/TAP interface i.e. through the VPN, but if the packet destination is within the IIIT network we can send it directly to the ethernet interface.</p>\n<p>The <code class=\"language-text\">ip</code> command is very powerful and allows us to do a lot of things with the routing table. Look at the <a href=\"http://man7.org/Linux/man-pages/man8/ip.8.html\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">ip command man page</a> for more intriguing usecases.</p>\n<p>We can add new routes using the <code class=\"language-text\">ip route add {params}</code> using a terminal or using the network settings. To keep things simple and to make sure that settings are persisted, I will make these changes in the network settings. This is detailed later in the post.</p>\n<p>If you are connected to a VPN your default route is set to TUN/TAP interface created by OpenVPN. To route all IIIT traffic to enp2s0 you can run the following command.</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">sudo</span> <span class=\"token function\">ip</span> route <span class=\"token function\">add</span> <span class=\"token number\">10.0</span>.0.0/8 via <span class=\"token number\">10.1</span>.34.1 dev enp2s0</code></pre></div>\n<p><code class=\"language-text\">10.0.0.0/8</code> which is equivalent to <code class=\"language-text\">10.x.x.x</code> which is the IP format for all devices on the IIIT network.\n<code class=\"language-text\">10.1.34.1</code> is the default gateway address for my wing in OBH.\nand <code class=\"language-text\">enp2s0</code> specifies the network interface to send the packet on.</p>\n<h2 id=\"Creating a WiFi Hotspot with create_ap\"> Creating a WiFi Hotspot with create_ap </h2>\nWhen I am in the IIIT network connected via ethernet I like to use a hotspot created from my laptop to connect my phone to the internet. I do this mainly because the Airtel/Jio reception in my hostel room is absolutely horrendous.\n<p>For doing this my recommended tool is <a href=\"https://github.com/oblique/create_ap\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">create_ap</a></p>\n<p>create_ap allows you to create an Access Point or Hotspot which other devices can connect to.\nInstalling the service is pretty straight forward and once you set up a persistent systemd service, you can set it up to start on boot. This means that whenever you start your laptop it will automatically set up an AP for your phone to connect to.</p>\n<p>If you face any issues with setting this up, let me know in the comments and I can write a more detailed post for the same. But here is the create_ap.conf which I use.</p>\n<div class=\"gatsby-code-title\">create_ap.conf</div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">CHANNEL=default\nGATEWAY=110.0.0.1\nWPA_VERSION=2\nETC_HOSTS=0\nDHCP_DNS=110.0.0.1,10.4.20.222,10.4.20.204,8.8.8.8\nNO_DNS=0\nNO_DNSMASQ=0\nHIDDEN=0\nMAC_FILTER=0\nMAC_FILTER_ACCEPT=/etc/hostapd/hostapd.accept\nISOLATE_CLIENTS=0\nSHARE_METHOD=nat\nIEEE80211N=0\nIEEE80211AC=0\nHT_CAPAB=[HT40+]\nVHT_CAPAB=\nDRIVER=nl80211\nNO_VIRT=1\nCOUNTRY=\nFREQ_BAND=2.4\nNEW_MACADDR=\nDAEMONIZE=0\nNO_HAVEGED=0\nWIFI_IFACE=wlp3s0\nINTERNET_IFACE=enp2s0\nSSID=ViolentDelights\nPASSPHRASE=Vi0lent3nds\nUSE_PSK=0</code></pre></div>\n<p>Here are the interesting parts:</p>\n<ol>\n<li><code class=\"language-text\">DHCP_DNS</code> specifies the DNS servers that all connected devices use for resolution. Here I have added <code class=\"language-text\">110.0.0.1</code> which is the dns server started by <code class=\"language-text\">create_ap</code>, <code class=\"language-text\">10.4.20.222</code> &#x26; <code class=\"language-text\">10.4.20.204</code> are the IIIT ns3 &#x26; ns4 servers respectively and <code class=\"language-text\">8.8.8.8</code> is a dns service by google for addresses on the internet.</li>\n<li><code class=\"language-text\">NO_VIRT</code> tells <code class=\"language-text\">create_ap</code> to not create a virtual network interface and to use the <code class=\"language-text\">WIFI_IFACE</code> for networking.</li>\n<li><code class=\"language-text\">WIFI_IFACE</code> specifies the interface to create the AP on &#x26; <code class=\"language-text\">INTERNET_IFACE</code> specifies the interface to forward the packets to. Here they are set to my WiFi IFACE and Ethernet IFACE respectively.</li>\n<li>If we set the <code class=\"language-text\">INTERNET_IFACE</code> to tun0 (created by OpenVPN) all packets received from the devices connected to the AP will be forwarded to the VPN! This is extremely useful as it allows the devices connected to the AP to <em>bypass the entire IIIT network</em> this means that any device which does not support proxy (PUBG on your phone, or the Xbox in your room) can connect to the internet with no issues whatsoever!</li>\n</ol>\n<h2 id=\"Steps for Automating\"> Steps for Automating </h2>\n<p>If you came to this blog post in hopes of quickly improving your network, the steps are below, but I really recommend that you go through the explanation above, this setup is not 100% stable and the above details will allow you to debug it if you ever need to. Also, it will broaden your understanding of networking in general.</p>\n<h3>1. Connect to IIIT network via LAN</h3>\n<ul>\n<li>Name this connection <code class=\"language-text\">Hostel Auth</code></li>\n<li>Ensure you have added your 802.1x creds</li>\n<li>Make sure you set the proxy to <code class=\"language-text\">None</code></li>\n<li>Go to IPv6 and set the method to Ignore (turning IPv6 off is not always recommended but I have not faced any issues yet and it seems to make the IIIT network a little bit faster)</li>\n<li>Wait for the connection to complete and confirm you can access both proxy.iiit.ac.in and facebook.com</li>\n</ul>\n<h3>2. Find the IP of your Default Gateway</h3>\n<ul>\n<li>run <code class=\"language-text\">ip route show</code></li>\n<li>The first line in the output is the default route</li>\n<li><code class=\"language-text\">default via 10.1.34.1 dev enp2s0 ...</code></li>\n<li>Write down the Default Gateway IP (For me it is: <code class=\"language-text\">10.1.34.1</code>)</li>\n</ul>\n<h3>3. Setup your VPN</h3>\n<ul>\n<li>Best way to set up an OpenVPN-based VPN on ubuntu is to install <code class=\"language-text\">network-manager-openvpn-gnome</code> using APT</li>\n<li>Go to network settings</li>\n<li>Create a new VPN</li>\n<li>Select import from OpenVPN config</li>\n<li>Select the correct .ovpn config file</li>\n<li>Save this as 'MyVPN' connection.</li>\n<li>Go to Proxy tab and enter IIIT Proxy details</li>\n<li>Go to IPv4 and set additional DNS servers to <code class=\"language-text\">10.4.20.204, 10.4.20.222, 8.8.8.8</code></li>\n<li>Go to IPv6 and set the method to Ignore (turning IPv6 off is not always recommended but I have not faced any issues yet and it seems to make the IIIT network a little bit faster)</li>\n</ul>\n<h3>4. Modify Hostel Auth network settings</h3>\n<div style=\"position:relative;height:0;overflow:hidden;max-width:100%;padding-bottom:66.66%;background-color:white;\">\n<img src=\"/hostelauth.jpeg\" alt=\"hostel-auth-network-settings\" style=\"position:absolute;top:0;left:0;width:100%;height:100%;\">\n</div>\n<center><span>Hostel Auth Settings will look similar to this</span></center>\n<ul>\n<li>The interface should look like the above</li>\n<li>Go to General tab and check 'Automatically connect to VPN when using this connection'</li>\n<li>select MyVPN from the dropdown</li>\n<li>Go to IPv4 Settings tab</li>\n<li>Set additional DNS servers to <code class=\"language-text\">10.4.20.204, 10.4.20.222, 8.8.8.8</code></li>\n<li>click on routes to open a new window</li>\n<li>Add a new route with Address='10.0.0.0' Netmask='8' Gateway='<code class=\"language-text\">IP from step 2</code>' metric='100'</li>\n<li>Save the settings</li>\n</ul>\n<h3>5. Setup hotspot using <code class=\"language-text\">create_ap</code> service</h3>\n<ul>\n<li>Install <a href=\"https://github.com/oblique/create_ap\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">create_ap</a></li>\n<li>Add a file with the following contents to /usr/lib/systemd/system</li>\n<li>Add create_ap.conf to /etc/</li>\n<li>Run <code class=\"language-text\">sudo systemctl daemon-reload</code> which will refresh the listing</li>\n<li>Run <code class=\"language-text\">sudo systemctl list-unit-files</code> and confirm that <code class=\"language-text\">create_ap.service</code> is present in the list</li>\n<li>Run <code class=\"language-text\">sudo systemctl enable create_ap.service</code> which will mark it to start on systemboot</li>\n</ul>\n<div class=\"gatsby-code-title\">/usr/lib/systemd/system/create_ap.service</div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">[Unit]\nDescription=Create AP Service\nAfter=network.target\n\n[Service]\nType=simple\nExecStart=/usr/bin/create_ap --config /etc/create_ap.conf\nKillSignal=SIGINT\nRestart=on-failure\nRestartSec=5\n\n[Install]\nWantedBy=multi-user.target</code></pre></div>\n<h3>6. PROFIT!</h3>\n<p>Now whenever your machine starts it will</p>\n<ul>\n<li>Connect to IIIT Network</li>\n<li>Connect to VPN</li>\n<li>Start a hotspot for your phone</li>\n<li>Configure route so that IIIT network resources are accessible</li>\n</ul>\n<h3>BONUS: When to set proxy</h3>\n<p>I use the above setup extensively, it allows me to access the internet via a VPN so I can access any service which might be blocked on IIIT network.</p>\n<p>It allows makes sure that all kinds of video calling applications work on my phone when it is connected to the hotspot and also that I don't have to change any settings when I try to open moodle or access the ada server.</p>\n<p>But some services don't like it when you connect to a VPN, for example, I had trouble getting Hotstar to work as it considered me to be in the Netherlands where its service is not available.</p>\n<p>To bypass this, I started using Hotstar in Firefox and set the proxy to proxy.iiit.ac.in inside the firefox settings. This ensures that all the traffic from firefox goes through the IIIT network and thus appears to Hotstar as a connection from within the country.</p>\n<h2 id=\"Conclusion\"> Conclusion </h2>\n<p>It is effective to play around with the various network settings available to you if you use Linux.\nIt shows how powerful, flexible, and most importantly fun a Linux machine can be.</p>\n<p>This is the first blog post I have written and it took a loooooong time for me to complete it, I am still learning and you - the reader - can be immensely helpful by sharing this with the rest of the IIIT janta.</p>\n<p>Drop any and all feedback in the comments below and let me know what I should write about next.\nIf you try the above setup and it does not work for you, or if you have any ideas how I can improve it, leave a comment or send me an email at <a href=\"mailto:blog-feedback@nemani.dev\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">blog-feedback@nemani.dev</a>.</p>"}},{"node":{"frontmatter":{"title":"/sbin/init: Why this blog?","description":"Hello World.","slug":"/blog/sbin-init","date":"2020-04-26","tags":["Talk","Misc"],"draft":false},"html":"<p>I am Arjun Nemani, a computer science student at IIIT-H and this is my personal blog.</p>\n<p>I have been thinking about writing about my technical exploits for a long time.</p>\n<p>The thought started out as a desire to emulate my role models, but it has grown a lot.</p>\n<div style=\"position:relative;height:0;overflow:hidden;max-width:100%;padding-bottom:56.25%;\">\n  <iframe src=\"https://giphy.com/embed/3oEjHWbXcpeKhTktXi\"\n    style=\"position:absolute;top:0;left:0;width:100%;height:100%;\"\n    frameborder=\"0\"\n    allowfullscreen>\n  </iframe>\n</div>\n<p>I now think that having a technical blog is essential for a person like me — someone who eats, breaths and sleeps tech.</p>\n<p>I feel that writing about your work allows you to think deeply and formalize the teachings of each day. Also, it is a great way of showcasing projects in depth.</p>\n<p>This will be a place for me to share my ideas, projects, and learnings from my various pursuits.\nWhile being mostly technical I will also share what I learned from organizing various events.</p>\n<p>Thank you for joining me on this journey of self-discovery and technology.</p>"}}]}},"pageContext":{}},"staticQueryHashes":["3115057458"]}